package com.we.flink.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

public class WeMexicoCpFile {
    public static Logger LOG = LoggerFactory.getLogger(WeMexicoCpFile.class);

    public static void copyFile(String srcFile, String dstFile) {
        try {
            InputStream inputStream =
                    WeMexicoCpFile.class.getClassLoader().getResourceAsStream(srcFile);
            File file = new File(dstFile);
            if (!file.exists()) {
                file.createNewFile();
            }

            BufferedInputStream in = new BufferedInputStream(inputStream);
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile));

            int len = -1;
            byte[] b = new byte[1024];
            while((len = in.read(b)) != -1) {
                out.write(b, 0, len);
            }

            in.close();
            out.close();

        } catch (Exception e) {
            LOG.error("WeMexicoCpFile excep: " + e.toString());
        }
    }

    public static void main(String[] args) {
        copyFile("hiveconf/hive-site.xml", "/tmp/hive-site1.xml");
        System.out.println("done!!");
    }
}
